#include "stdafx.h"
#include "normal.h"

void openDirectory()
{
	TCHAR szExeFile[MAX_PATH]={0};
	TCHAR szExeCMD[MAX_PATH]={0};

	//get the full path of the exe file
	GetModuleFileName(NULL,szExeFile,sizeof(szExeFile));

	wcscpy_s(szExeCMD,_T("EXPLORER.EXE")) ;

	for (UINT nLen =0; nLen<wcslen(szExeFile) ;nLen++)
	{

		if (szExeFile[nLen]=='.'&&szExeFile[nLen+4]=='\0')
		{
			//remove the exe suffix , then get the directory path
			szExeFile[nLen]='\0' ;
			wcscat_s(szExeCMD,_T(" "));
			wcscat_s(szExeCMD,szExeFile);		

			//szExeFile is the path of the directory
			//szExeCMD is the explorer.exe cmd to open the target directory

			WIN32_FIND_DATA wfd ;
			HANDLE hFindFile = FindFirstFile(szExeFile, &wfd);
			if (hFindFile == INVALID_HANDLE_VALUE) 
			{
				printf ("Invalid File Handle. GetLastError reports %d\n", 
					GetLastError ());
			} 
			else
			{
				USES_CONVERSION;
				WinExec(T2A(szExeCMD),SW_SHOW);
			}
		}
	}
}